$(function () {
  let carousel = layui.carousel;
  //获取轮播图
  $.ajax({
    url: '/api/swipers',
    success(res) {
      if (res.status != 0) return;
      let data = res.data;
      data.forEach((item) => {
        $(`<li class="img-effect">
                <a href="javascript:;">
                  <img src="http://localhost:8888/uploads/${item.swiperimg}" alt="" />
                </a>
              </li>`).appendTo($('.kr_carousel_wrap'));
        carousel.render({
          elem: '#kr_carousel',
          width: 720,
          height: 300,
          interval: 3000,
        });
      });
    },
  });
  //获取友情链接
  $.ajax({
    url: '/api/links',
    success(res) {
      if (res.status != 0) return;
      let data = res.data;
      console.log(data);
      data.forEach((item) => {
        if (item.linkurl.indexOf('https') != -1) {
          $(`<dd>
                <a href="${item.linkurl}"target="_blank">
                  <img src="./uploads/${item.linkicon}" alt="${item.linkdesc}" />
                </a>
              </dd>`).appendTo('.kr_collaborator');
        } else {
          $(`<dd>
                <a href="${item.linkurl}"target="_blank">
                  <img src="http://localhost:8888/uploads/${item.linkicon}" alt="${item.linkdesc}" />
                </a>
              </dd>`).appendTo('.kr_collaborator');
        }
      });
    },
  });
});
